
package Helper;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import java.util.ArrayList;

/**
 * Teilt Große Tilesets auf und gibt sie als ArryList zurueck
 * @author Robin
 */
public class Tile {
    
    
    public ArrayList<Image> getTiles(String picture, int tileSize){
	return getTiles(picture,tileSize,tileSize);
    }
	    
    public ArrayList<Image> getTiles(String picture, int tileSizeX, int tileSizeY){
	return getTiles(picture,tileSizeX,tileSizeY,0);
    }	    
	    
    public ArrayList<Image> getTiles(String picture, int tileSizeX, int tileSizeY , int offSet){
	return getTiles(picture,tileSizeX,tileSizeY,offSet,offSet);
    }	
	    
    public ArrayList<Image> getTiles(String picture, int tileSizeX, int tileSizeY , int offSetX , int offSetY){
	try{
	    
	    Image image = new Image(picture);
	    ArrayList tileArray = new ArrayList();

	    int x = (int)(((image.getWidth()-offSetX))/tileSizeX);
	    int y = (int)(((image.getHeight()-offSetY))/tileSizeY);
	    
	    
	    
	    for(int j = 0; j<x ; j++){
		for(int i = 0; i<y; i++){
		    System.out.println(j*tileSizeX+offSetX + "," + (i*tileSizeY+offSetY));
		    System.out.println(j + "," + i);
		    
		    
		    tileArray.add(image.getSubImage(j*tileSizeX+offSetX, i*tileSizeY+offSetY, tileSizeX, tileSizeY));
		}
	    }
	    
	    return tileArray;
	}catch(SlickException e){
	    return null;
	}
    }    
}
